package com.kfm.boot.http;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.kfm.boot.entity.Message;
import com.kfm.boot.entity.Question;

import java.util.ArrayList;

public class HttpTest {

    public static void main(String[] args) {
//        String s = HttpUtil.post("http://localhost:8080/post", "");
//        System.out.println(s);
//        ArrayList<Message> messages = new ArrayList<>();
//        messages.add(new Message("user","java 连接数据库"));
//        Question question = new Question("gpt-3.5-turbo", messages);
        // 对象转json
//        String jsonStr = JSONUtil.toJsonStr(question);
        String url = "https://api2.ycdl.pro/v1/chat/completions";
        String json = "{\n" +
                "  \"model\": \"gpt-3.5-turbo\",\n" +
                "  \"messages\": [{\"role\": \"user\", \"content\": \"this is a test.\"}]\n" +
                "}";
        String result2 = HttpRequest.post(url)
                .header(Header.CONTENT_TYPE, "application/json")//头信息，多个头信息多次调用此方法即可
                .header(Header.AUTHORIZATION, "Bearer sk-***")
                .body(json)// 请求体内容
//                .timeout(20000)//超时，毫秒
                .execute().body();
        System.out.println(result2);
//        User kfm = new User("kfm", 12);
//        System.out.println(kfm.getName());
//        System.out.println(kfm.getAge());

    }
}
